home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / X11 / lib / misc.c < prev    next >
C/C++ Source or Header  |  1995-05-03  |  1KB  |  62 lines

  1. /* routines to center a window on a screen.
  2.  * center_vertical() takes as arguments a display, window and window height.
  3.  * it reconfigures the window to be centered vertically.
  4.  */
  5.  
  6. #include <X11/Xlib.h>
  7.  
  8. void
  9. center_vertical(dpy, w, height)
  10. Display *dpy;
  11. Window w;
  12. int height;
  13. {
  14.     Window root, child;
  15.     int top, x, y, rootX, rootY;
  16.     unsigned int bw, d, new_w, new_h;
  17.     XWindowChanges values;
  18.  
  19.     XGetGeometry(dpy,w,&root,&x,&y,&new_w,&new_h,&bw,&d);
  20.     XTranslateCoordinates(dpy, w, root, 0, 0, &rootX, &rootY, &child);
  21.     top = XDisplayHeight(dpy, DefaultScreen(dpy)) - height;
  22.     y = (top/2) - rootY;
  23.     if (y < 0)
  24.         y = -y;
  25.     if (y > 0) {
  26.         values.y = (top - (2*y)) / 2,0;
  27.         if (values.y < 0)
  28.             values.y = 0;
  29.         XConfigureWindow(dpy,w,CWY,&values);
  30.     }
  31. }
  32.  
  33. /* 
  34.  * center_horizontal() takes as arguments a display, window and window width.
  35.  * it reconfigures the window to be centered horizontally.
  36.  */
  37.  
  38. void
  39. center_horizontal(dpy, w, width)
  40. Display *dpy;
  41. Window w;
  42. int width;
  43. {
  44.     Window root, child;
  45.     int left, x, y, rootX, rootY;
  46.     unsigned int bw, d, new_w, new_h;
  47.     XWindowChanges values;
  48.  
  49.     XGetGeometry(dpy,w,&root,&x,&y,&new_w,&new_h,&bw,&d);
  50.     XTranslateCoordinates(dpy, w, root, 0, 0, &rootX, &rootY, &child);
  51.     left = XDisplayWidth(dpy, DefaultScreen(dpy)) - width;
  52.     x = (left/2) - rootX;
  53.     if (x < 0)
  54.         x = -x;
  55.     if (x > 0) {
  56.         values.x = (left - (2*x)) / 2, 0;
  57.         if (values.x < 0)
  58.             values.x = 0;
  59.         XConfigureWindow(dpy,w,CWX,&values);
  60.     }
  61. }
  62.